package com.chongzi.cloud;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class code3 {
    public int lengthOfLongestSubstring(String s) {
        int begin=0;
        int res=0;
        HashMap<Character, Integer> map = new HashMap<>();
        for (int end=0;end<s.length();end++){
            char c = s.charAt(end);
            if (map.containsKey(c)){
                begin=Math.max(map.get(c)+1,begin);
                map.put(c,end);
            }else {
                map.put(c,end);
            }
            res=Math.max(end-begin+1,res);

        }return res;
    }


}

